package zzzhc.image.recognize.nn;

import zzzhc.image.recognize.ImageToken;

public class NNInputItem {
	private double[] data;

	private char code;

	private transient ImageToken token;

	public NNInputItem() {

	}

	public static NNInputItem fromImageToken(ImageToken token) {
		double[] data = new double[token.w * token.h];
		for (int y = 0; y < token.h; y++) {
			for (int x = 0; x < token.w; x++) {
				data[y * token.w + x] = token.data[y][x];
			}
		}
		NNInputItem item = new NNInputItem(data);
		return item;
	}

	public static NNInputItem fromImageToken(ImageToken token, char code) {
		NNInputItem item = fromImageToken(token);
		item.setCode(code);
		item.token = token;
		return item;
	}

	public NNInputItem(double[] data) {
		setData(data);
	}

	public NNInputItem(double[] data, char code) {
		setData(data);
		setCode(code);
	}

	public char getCode() {
		return code;
	}

	public void setCode(char code) {
		this.code = code;
	}

	public double[] getData() {
		return data;
	}

	public void setData(double[] data) {
		this.data = data;
	}

	public String getDataString() {
		if (data == null) {
			return "";
		}
		StringBuilder sb = new StringBuilder();
		for (double d : data) {
			sb.append(d).append(";");
		}
		if (sb.length() > 0) {
			sb.setLength(sb.length() - 1);
		}
		return sb.toString();
	}

	public ImageToken getImageToken() {
		return token;
	}
}
